<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Config;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        echo Config::get('path');
//        $this->success('请求成功');
    }
    
    public function task(){
        $data = file_get_contents("https://api.thickink.com/api/demandPool/list?page=1&pageSize=10000&state=2&day=360");
        $fileData = json_decode($data,true);
        if ($fileData['code']=='0' && $fileData['message']=='success'){
            for ($i=0;$i<count($fileData['data']);$i++){
                $task['id']=$i+1;
                $task['name']=base64_encode($fileData['data'][$i]['userName']);
                $task['com']=$fileData['data'][$i]['companyName'];
                $task['position']=$fileData['data'][$i]['companyPosition'];
                $task['wechat']=$fileData['data'][$i]['weixin'];
                $task['supply']=$fileData['data'][$i]['resourcesProvided'];
                $task['need']=base64_encode($fileData['data'][$i]['resourcesNeeded']);
                $task['_id']=$fileData['data'][$i]['id'];
                $task['area']=$fileData['data'][$i]['cooperationArea'];
                $task['time']=time();
                Db::name('task')->data($task)->insert();
                $taskId = Db::name('task')->getLastInsID();
                if ($taskId>0){
                    echo '存入数据成功'.$taskId;
                }
            }
        }
    }

    /**
     * @return
     */
    public function getAuth()
    {
       echo base64_decode('6LW15LqR5b+XLemrmOagoQ==');
    }
}
